use strict;
use warnings;
use Data::Dumper;
use Test::More 'no_plan';

use testsupport;

use_ok('Log');
use_ok('Model');


my $log= Log->instance;
$log->setlevels('DEBUG',3);

my $model = Model->new( root => "./data");

$model->read_model();

is($model->exists('CONTAINER'),1,"CONTAINER do not exists");
is($model->exists('not exists CONTAINER'),0,"exist!");
is($model->exists('requirement'),0,"exists");
is($model->exists('REQUIREMENT'),1,"REQUIREMENT do not exists");
is($model->exists('TEXT'),0,"TEXT do not exists");

# $model->dump();

is($model->check_isTerminal('not exists'),undef,"");
is($model->check_isTerminal('TEXT'),1,"TEXT is not a Terminal");
is($model->check_isTerminal('COMPLEX_TEST_SPEC'),0,"COMPLEX_TEST_SPEC is not a Non Terminal");
is($model->check_isTerminal('REQUIREMENT'),0,"REQUIREMENT is not a Non Terminal");


is($model->check_isLeaf('REQUIREMENT'),1,"REQUIREMENT is not 1");
is($model->check_isLeaf('not exists'),undef,"'not exists' is not undef");
is($model->check_isLeaf('TEXT'),undef,"TEXT leaf is not undef");
is($model->check_isLeaf('TICKET'),0,"TICKET leaf is not 0 ");
is($model->check_isLeaf('TICKET_POST'),1,"TICKET_POST leaf is not 1 ");

$log->xinfo($log->nou,"test");

# a file conf that not exists:
eval {
    $model = Model->new( root => "./data", modelfile => "MODEL_do_not_exists.CONF");
};
check_uuid(__FILE__,__LINE__,"82cc4eeb-6b4e-3351-a5bb-f02497f7e918",$@);

# a root directory that not exists:
eval {
    $model = Model->new( root => "./do_not_exist", modelfile => "MODEL.CONF");
};
check_uuid(__FILE__,__LINE__,"a6e04cbc-d8e3-35d1-9110-79fb00ea0a5f",$@);

# a file with an asterisc (*) deleted in a left-part of rule:
eval {
    $model = Model->new( root => "./data", modelfile => "MODEL_del_a_star.CONF");
    $model->read_model();
};
check_uuid(__FILE__,__LINE__,"a4cd1148-2118-3c95-abe9-e94b77bbf457",$@);


# some _ checks:
foreach my $i (1..3) {
    eval {
	$model = Model->new( root => "./data", modelfile => "MODEL_with_underscore$i.CONF");
	$model->read_model();
    };
    check_uuid(__FILE__,__LINE__,"8d1cf906-5f6a-3f24-aec7-73d6e755437b",$@);
}



# check_uuid(__FILE__,__LINE__,
# if($@) {
#    print STDERR "$@";
# }














